#pragma once
#include <iostream>
#include <assert.h>


using namespace std;

class Date
{
public:
	bool CheckInvalid() const;
	Date(int year = 1, int month = 1, int day = 1);

	bool operator<(const Date& d) const;
	bool operator<=(const Date& d)const;
	bool operator>(const Date& d)const;
	bool operator>=(const Date& d)const;
	bool operator==(const Date& d)const;
	bool operator!=(const Date& d)const;

	// d1 + 100
	// 
	Date& operator+=(int day);//日期+=天数
	Date operator+(int day)const; //日期 + 天数
	Date operator-(int day)const;// 日期-天数
	Date operator-=(int day);// 日期-=天数

	//d1++
	Date& operator++();//前置++

	//特殊处理：解决语法逻辑不自洽，自相矛盾的问题
	//++d1
	//为了跟前置++区分，强行增加一个int形参，构成重载区分
	Date operator++(int);//后置++
    
	Date& operator--();//前置--
	Date operator--(int);//后置--
	
	// d1 - d2

	// 日期-日期 返回天数,即日期差
	int operator-(const Date& d);

	//本质就是inline
	int GetMonthDay(int year, int month)const
	{
		assert(month > 0 && month < 13);
		int monthDays[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		if ((month == 2) && (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
		{
			return 29;
		}
		return monthDays[month];
	}
	
	void Print() const
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}

	// 友元声明
	//friend ostream& operator<<(ostream& out, const Date& d);
	//friend istream& operator>>(ostream& in, Date& d);
	

//private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& out, const Date& d);
istream& operator>>(istream& in, Date& d);